﻿using System.Web.Mvc;
using Fuse8.ContentManagementFramework.BizFacade.Services;
using Fuse8.ContentManagementFramework.Domain;
using Fuse8.ContentManagementFramework.Web.MvcPowered;
using Fuse8.DomainFramework.Common.Locator;

namespace Fuse8.ContentManagementFramework.Web.Extensions
{
	public static class ControllerExtensions
	{
		public static CmsPage GetCmsContextPage (this Controller controller)
		{
			return DependencyServiceLocator.Current.GetInstance<ICmsContext>().ContextPage;
		}

		public static ActionResult RedirectToCmsContextPage(this Controller controller)
		{
			var contextPage = controller.GetCmsContextPage();
			return new RedirectResult(contextPage != null ? contextPage.PageUrl : "/");
		}
	}
}